package com.ec.system.modules.sys.controller;

import com.ec.core.common.core.api.Result;
import com.ec.core.common.core.api.ResponseMsg;
import com.ec.core.mybatis.groups.AddGroup;
import com.ec.core.mybatis.groups.DeleteGroup;
import com.ec.core.mybatis.groups.OtherGroup;
import com.ec.core.mybatis.groups.UpdateGroup;
import com.ec.system.modules.sys.dto.SysTopMenuDTO;
import com.ec.system.modules.sys.service.ISysTopMenuService;
import com.ec.system.modules.sys.vo.SysTopMenuVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 顶部菜单接口
 * @author: Eric Lee
 * @time: 2021/8/6 15:13
 */
@RestController
@RequestMapping("/top-menu")
public class SysTopMenuController {
    @Resource
    private ISysTopMenuService sysTopMenuService;

    /**
     * 顶部菜单列表
     *
     * @return
     */
    @GetMapping("/list")
    public Result<List<SysTopMenuVO>> listTopMenu() {
        return ResponseMsg.success(sysTopMenuService.listTopMenu());
    }

    /**
     * 获取顶部菜单路由
     *
     * @return
     */
    @GetMapping
    public Result<List<SysTopMenuVO>> getTopMenu() {
        return ResponseMsg.success(sysTopMenuService.getTopMenu());
    }

    /**
     * 添加菜单
     *
     * @return
     */
    @PostMapping
    public Result<Void> addTopMenu(@Validated(AddGroup.class) @RequestBody SysTopMenuDTO sysTopMenuDTO) {
        return ResponseMsg.status(sysTopMenuService.addTopMenu(sysTopMenuDTO));
    }

    /**
     * 更新操作
     *
     * @param sysTopMenuDTO
     * @return
     */
    @PutMapping
    public Result<Void> updateTopMenu(@Validated(UpdateGroup.class) @RequestBody SysTopMenuDTO sysTopMenuDTO) {
        return ResponseMsg.status(sysTopMenuService.updateTopMenu(sysTopMenuDTO));
    }

    /**
     * 删除操作
     *
     * @param topMenuId
     * @return
     */
    @DeleteMapping("/{topMenuId}")
    public Result<Void> deleteTopMenu(@Validated(DeleteGroup.class) @PathVariable Long topMenuId) {
        SysTopMenuDTO sysTopMenuDTO = new SysTopMenuDTO();
        sysTopMenuDTO.setTopMenuId(topMenuId);
        return ResponseMsg.status(sysTopMenuService.deleteTopMenu(sysTopMenuDTO));
    }

    /**
     * 配置顶部菜单的下级菜单
     *
     * @param sysTopMenuDTO
     * @return
     */
    @PutMapping("/configTopMenu")
    public Result<Void> configTopMenu(@Validated(OtherGroup.class) @RequestBody SysTopMenuDTO sysTopMenuDTO) {
        return ResponseMsg.status(sysTopMenuService.configTopMenu(sysTopMenuDTO));
    }
}
